<template>
  <div id="private-head">
    <div class="wrap">
      <div class="left private_left">
        <router-link to="/">
          <svg class="icon private_icon" aria-hidden="true">
            <use xlink:href="#icon-icon_xiangji"></use>
          </svg>
        </router-link>
      </div>
      <div class="search search_head">
        <button>
          <svg class="button_icon" aria-hidden="true">
            <use xlink:href="#icon-sousuo2"></use>
          </svg>
        </button>
        <input type="text" v-model="searchValue" placeholder="search for something you need">
      </div>
      <div class="right" v-if="!userName">
        <div class="admin_login" @click="HandlerAdminLog()">我是管理员</div>
        <div class="right_login" @click="HandlerLog()">
          <span>登录</span>
          <i class="iconfont icon-denglu1"></i>
        </div>
        <div class="right_reg" @click="HandlerReg()">
          注册
          <i class="iconfont icon-zhuce1"></i>
        </div>
      </div>
      <div class="right" v-else>
        <div>
          <form enctype="multipart/form-data">
            <div style="display:inline">
              <Icon type="ios-cloud-upload" size="52"></Icon>
              <input name="pic" type="file" ref="fileForm" class="uploadStyle">
            </div>
            <input type="submit" value="提交" @click="handerpho()" class="submitStyle">
          </form>
        </div>
        <div class="right_login">
          <i class="iconfont icon-notice"></i>
        </div>
        <div class="right_reg">
          <Dropdown trigger="custom" :visible="visible">
            <p @click="handleOpen">
              <i class="iconfont icon-iconzhucetouxiang"></i>
            </p>
            <DropdownMenu slot="list">
              <div style="text-align: right;margin:10px;">
                <Button type="primary" @click="handleClose">退出</Button>
              </div>
            </DropdownMenu>
          </Dropdown>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "PrivateHead",
  data() {
    return {
      visible: false,
      userName: sessionStorage.userName,
      searchValue: ""
    };
  },
  methods: {
    handerpho() {
      var file = this.$refs.fileForm.files[0];
      var formdata1 = new FormData(); // 创建form对象
      console.log(file);
      formdata1.append("pic", file); // 通过append向form对象添加数据,可以通过append继续添加数据
      let config = {
        headers: { "Content-Type": "multipart/form-data" }
      }; //添加请求头
      axios.post("api/save", formdata1, config).then(response => {
        console.log(response.data);
      });
    },
    handleOpen() {
      this.visible = true;
    },
    handleClose() {
      this.visible = false;
      sessionStorage.clear();
      this.$router.push("/Login");
    },
    HandlerAdminLog() {
      this.$router.push("/AdminLogin");
    },
    HandlerReg() {
      this.$router.push("/Register");
    },
    HandlerLog() {
      this.$router.push("/Login");
    }
  }
};
</script>

<style scoped>
.submitStyle{
    background-color: #fff;
    color: #000;
    border: none;
    border-radius: 20px;
    padding: 10px 6px;
    margin-left: 5px;
}
.submitStyle:focus{
    outline: none;
}
.uploadStyle {
  width: 50px;
  position: absolute;
  top: 14px;
  right: 225px;
  opacity: 0;
}
.wrap {
  background-color: black;
}
.private_icon {
  width: 78%;
}
.private_left {
  width: 5%;
}
.right_login {
  margin-left: 25px;
  padding-right: 15px;
}
.right_reg {
  margin: 0 15px;
}
.ivu-btn-primary.active,
.ivu-btn-primary:active,
.ivu-btn-primary:hover {
  color: #fff !important;
}
.ivu-btn-primary {
  color: #fff;
  background-color: #000;
  border-color: #000;
}
.ivu-dropdown-menu {
  min-width: auto;
}
</style>
